<?php

class TestimoniesController extends Controller {

    public $layout = 'column2';

    public function actionIndex() {
        $model = new WebGuestbook;
        if (isset($_POST['WebGuestbook']) && isset(Yii::app()->request->cookies['member_uid'])) {
            $uid = Yii::app()->request->cookies['member_uid']->value;
            $member = WebCustomers::model()->findByPk($uid);
            $model->attributes = $_POST['WebGuestbook'];
            $model->username = $member->fast_name;
            $model->email = Yii::app()->request->cookies['member_mail']->value;
            $model->state = 0;
            $model->re_content = 'Thank you for your support to us';
            $model->add_time = Date('Y-m-d');
            $model->ip = Yii::app()->request->userHostAddress;
            if ($model->save()) {
                $this->redirect($this->createUrl('index', array('message' => 'Message success')));
            }
        }
        $model->state = 1;
        $this->render('index', array('model' => $model));
    }

}
